<?php
class pinyin {

    private $obj = null;

    public function input( $obj ) {
        $this->obj = $obj;
    }

    public function version() {
        return array(
            'version' => '1.0',
            'pid' => 'pinyin',
            'description' => '自动将标题转换成拼音',
            'home' => 'http://blog.com',
            'author' => '幽灵传说',
            'status' => 1
        );
    }

    public function add_post( $date ) {
        $date = $date[ 0 ];
        if ( !empty( $date[ 'alias' ] ) ) return;

        require APP_PLUGIN . "pinyin/pinyin_lib.php";
        $lib = new pinyin_lib();
        $date[ 'alias' ] = $lib->output( $date[ 'title' ] );

        $where = array( 'id' => $date[ 'id' ] );
        unset( $date[ 'id' ] );
        $this->obj->model->table = 'article';
        $this->obj->model->update( $where, $date );
    }
}